package acm.蓝桥12;

import java.util.Scanner;

public class 最长括号 {
    static int n, m;
    static int maxN = 1000001;
    static char[] chars;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        sc.nextLine();
        chars = sc.nextLine().toCharArray();
        for (int i = 0; i < m; i++) {
            int op = sc.nextInt();
            int l = sc.nextInt() - 1;
            if (op == 1) {
                int r = sc.nextInt() - 1;
                fz(l, r);
            } else {
                int len = query(l);
                System.out.println(len);
            }
        }
    }

    static char[] flip = new char[128];

    {
        flip[')'] = '(';
        flip['('] = ')';
    }

    private static int query(int l) {
        int cnt = 0;
        int res = 0;
        for (int i = l; i < chars.length; i++) {
            if (chars[i] == ')') {
                cnt--;
            } else {
                cnt++;
            }
            if (cnt < 0) break;
            if (cnt == 0) res = i;
        }
        if (res == 0) {
            return 0;
        } else {
            return res + 1;
        }
    }

    private static void fz(int l, int r) {
        while (r > l) {
            chars[l] = flip[chars[l]];
            l++;
        }
    }
}
